package org.devocean.groupbuying.web.backend;


import javax.servlet.http.HttpSession;

import org.springframework.security.core.context.SecurityContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller

@RequestMapping(value = { "/gb-cpanel" })

public class HomeController {

	@RequestMapping("/")
	public String index() {

		return "backend.definition";
	}
	
	@RequestMapping("/session")
	public String getSession(HttpSession session) {
		
		SecurityContext sc = (SecurityContext) session.getAttribute("SPRING_SECURITY_CONTEXT");
		if(sc != null){
			System.out.println("oui");
			return "{success:true}";
		}
		else{
			System.out.println("non");
			return "{success:false}";
		}
	}
	
	@RequestMapping(value="/login")
	public String login(ModelMap model) {
		return "login/backendlogin";
 
	}
	
	@RequestMapping(value="/logout", method = RequestMethod.GET)
	public String logout(ModelMap model) {
		return "login/backendlogin"; 
	}

	
	@RequestMapping(value="/loginfailed", method = RequestMethod.GET)
	public String loginerror(ModelMap model) {
		model.addAttribute("error", "true");
		return "login/backendlogin";
 
	}

}
